package com.db.compare.service.impl;

import com.db.compare.model.RbacUser;
import com.db.compare.service.RbacUserService;
import com.db.compare.utils.SecurityUtils;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

/**
 * 获取上下文
 * */
public class Appcontext {

    public static String getUserMobile(){

        return SecurityUtils.getUsername();
    }

    public static RbacUser getCurrentUser(){
        RbacUserService rbacUserService =SpringUtil.getBean(RbacUserService.class);
        return rbacUserService.findByUserPhone(getUserMobile());
    }

    public static ServletOutputStream downloadResponse(HttpServletResponse response, String fileName)throws Exception{
        response.setCharacterEncoding("UTF-8");
        response.setHeader("content-type", "application/octet-stream;charset=UTF-8");
        response.setContentType("application/octet-stream;charset=UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + new String( fileName.getBytes("gb2312"), "ISO8859-1" ) + ".xlsx");
        ServletOutputStream outputStream = response.getOutputStream();
        return outputStream;
    }
}
